<?php
class IndexController extends Controller{
		public function __construct(){
		$this->path = ROOT_PATH . '/mdb/userdata.php';
		$this->dataPath = ROOT_PATH . '/mdb/data.php';
		$this->db = include $this->path; //管理员信息
		$this->data = include $this->dataPath;
		$this->Wid = (empty($_GET['id']))?0:$_GET['id'];
		}
	public function index(){
//		加载模板
		$this->display();
//		登录判断
		 if(IS_POST){
			if($_POST['username'] == $this->db['username'] && $_POST['password'] == $this->db['password']){
				$_SESSION['username'] = $_POST['username'];
				setcookie(session_name(),session_id(),0,'/');
				$this->success('登录成功','./admin.php?c=Index&a=admin');
			
			}
			else{
				$this->error('账号或密码不正确请重新登录');
			}
		}
	}
	/*
	 * 判断是否合法路径访问  是否登录 
	 */
	public function Islogin(){
			if(empty($_SESSION['username'])){
				$this->success('不合法路径,请登录后执行操作',__ROOT__ .'/admin.php?c=Index');
			};
	}
/*
 * 管理首页
 */	
	public function admin(){
			$this->Islogin();
		$this->display();
	}
	/*
	 * 登出
	 */
	 public function LoginOut(){
	 	$this->Islogin();
	 	session_unset();
		session_destroy();
		$this->success('注销成功','./index.php');
	 }
//	 显示验证码
	public function Code(){
		$code =new Code();
		$code->ImgCodeShow();
		
	}
//	遍历内容
	public function wishContro(){
		$this->Islogin();
		$this->display();
	}
	/*
	 * 删除内容
	 */
	 public function delContent(){
	 	$this->Islogin();
//	 	删除信息
	 	unset($this->data[$this->Wid]);
		$phpCode =var_export($this->data,true);
		data_to_file($this->data, $this->dataPath);
		$this->success('删除成功', './admin.php?c=Index&a=wishContro');
	 }
	 public function editContent(){
	 	$this->Islogin();
	 	$this->display();
	 	if($_POST){
			$this->data[$this->Wid]=$_POST;
			$phpCode =var_export($this->data,true);
			data_to_file($this->data, $this->dataPath);
			$this->success('编辑成功', './admin.php?c=Index&a=wishContro');
		}
	 }
	 	public function Welcome(){
		$this->display();
	}
}
?>